from django import forms
from django.core.exceptions import ValidationError

from IM import models
from IM.models import AuthUser


# class MySelectDateWidget(forms.SelectDateWidget):
#     class Media:
#         css = {
#             'all': ('common.css',)
#         }
#
#     # def __init__(self, *args, **kwargs):
#     #     super(MySelectDateWidget, self).__init__(years=("1999", "2000", "2001"), *args, **kwargs)


class UserForm(forms.ModelForm):
    class Meta:
        model = AuthUser
        fields = ["avatar", "username", "password"]

class ImageForm(forms.ModelForm):
    class Meta:
        model = models.Image
        fields = ['image']
    # avatar = forms.ImageField(required=True, label="头像")
    # username = forms.CharField(max_length=50, label="用户名", required=False,help_text="")
    # sex = forms.ChoiceField(widget=forms.RadioSelect, label="性别", choices=(("1", "男人"), ("2", "女人")))
    # password = forms.CharField(max_length=50, label="密码")
    # email = forms.EmailField(max_length=100, label="邮箱")
    # birthday = forms.DateField(widget=MySelectDateWidget, label="出生日期")
    # hobby = forms.MultipleChoiceField(widget=forms.CheckboxSelectMultiple,
    #                                   choices=(
    #                                       ('blue', 'Blue'),
    #                                       ('green', 'Green'),
    #                                       ('black', 'Black'),
    #                                   ),
    #                                   label="爱好"
    #                                   )
    # description = forms.CharField(label="用户简介", widget=forms.Textarea)

    # username.widget.attrs.update({"style": "color:red;"})

    # def full_clean(self):
    #     print(self.data)
    #     if self.data and self.data['username'] == 'zhangshan':
    #     # print(dir(self.fields['username']))
    #     # if self.fields['username'] == "zhangshan":
    #         raise ValidationError("This value can not be zhangshan")
    #     super(UserForm, self).full_clean()